package com.shh.rabbitmq.topic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicRabbitMqConfiguration {

	 //1.声明注册topic模式的交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic_order_exchange",true,false);
    }
    //2.声明队列
    @Bean
    public Queue topicsmsQueue(){
        return new Queue("sms.topic.queue",true);
    }
    @Bean
    public Queue topicduanxinQueue(){
        return new Queue("duanxin.topic.queue",true);
    }
    @Bean
    public Queue topicemailQueue(){
        return new Queue("email.topic.queue",true);
    }
    //3.完成绑定关系,#匹配0个或多个单词，*匹配不多不少一个单词 com.duanxin.sms   匹配到sms/duanxin两个队列
    @Bean
    public Binding topicsmsBingding(){
        return BindingBuilder.bind(topicsmsQueue()).to(topicExchange()).with("#.sms.#");
    }
    @Bean
    public Binding topicduanxinBingding(){
        return BindingBuilder.bind(topicduanxinQueue()).to(topicExchange()).with("*.duanxin.#");
    }
    @Bean
    public Binding topicemailBingding(){
        return BindingBuilder.bind(topicemailQueue()).to(topicExchange()).with("*.email.com");
    }
}
